/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hu.arguscab.ai.game;

import hu.arguscab.ai.FitnessFunction;
import hu.arguscab.ai.Model;
import hu.arguscab.game.CompoundAction;
import hu.arguscab.game.GameAction;
import hu.arguscab.game.WorldState;

/**
 *
 * @author sharp
 */
public class FAction extends FitnessFunction{

	private int throttleCost= 100;
	private int breakCost	=  60;
	private int leftCost	=  30;
	private int rightCost	=  30;
	private int haltCost	=   0;

	@Override
	public float getMinValue() {
		return 0;
	}

	@Override
	public float getMaxValue() {
		return 100;
	}


	@Override
	public float calcF(Model m) {
		WorldState state = (WorldState)m.getState();
		//Vector target = state.getTarget();
		CompoundAction actions = state.getShipState().getCurrentActionsCopy();
		boolean isHalting = true;
		int cost = 0;
		if ( actions.hasAction(GameAction.THROTTLE) ) {
			cost += throttleCost;
			isHalting = false;
		}
		if ( actions.hasAction(GameAction.BREAK) ) {
			cost += breakCost;
			isHalting = false;
		}
		if ( actions.hasAction(GameAction.LEFT) ) {
			cost += leftCost;
			isHalting = false;
		}
		if ( actions.hasAction(GameAction.RIGHT) ) {
			cost += rightCost;
			isHalting = false;
		}
		if ( isHalting )
			cost = haltCost;

		return cost;
	}
}
